import { login } from '@/api/user.js'
import { getToken, setToken } from '@/utils/auth.js'

const state = {
  token: getToken() || ''
}
const mutations = {
  saveToken(state, value) {
    state.token = value
    setToken(value)
  }
}
const actions = {
  async toLogin(store, value) {
    // 调用登录接口
    const res = await login(value)
    // 储存token
    store.commit('saveToken', res.data)
    console.log('登录成功res:', res)
  }
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
